package com.niit.utils;

import lombok.Data;

import java.io.Serializable;

/**
 * 统一返回对象Result
 *
 * @author makejava
 * @since 2024-06-04 09:16:57
 */
@Data
public class Result implements Serializable {
    private static final long serialVersionUID = -22459500732598085L;
    private int code;
    private String msg;
    private long count;
    private Object data;

    /**
     * 设置数据
     *
     * @param data 数据
     * @return Result
     */
    public Result setData(Object data) {
        this.data = data;
        return this;
    }

    public static Result success(){
        Result r = new Result();
        r.code = 200;
        r.count=0;
        r.msg="登录成功！";
        return  r;
    }

    public static Result fail1(){
        Result r = new Result();
        r.code = 401;
        r.msg="登录失败了，请重新登录！";
        return  r;
    }

    /**
     * 操作成功
     *
     * @return Result
     */
    public static Result ok() {
        Result r = new Result();
        r.code = 0;
        r.msg = "OK";
        r.count=10;
        System.out.println("注册成功了！");
        return r;
    }

    /**
     * 认证授权失败。 包括密钥信息不正确；数字签名错误；授权已超时
     *
     * @return Result
     */
    public static Result fail() {
        Result r = new Result();
        r.code = 401;
        r.msg = "fail";
        r.count=10;
        System.out.println("注册失败了！");
        return r;
    }

    /**
     * 系统异常
     *
     * @return Result
     */
    public static Result exp() {
        Result r = new Result();
        r.code = 500;
        r.msg = "exception";
        return r;
    }
}

